Data storage device and method for rewriting parameters thereof

ABSTRACT

A data storage device is provided. The data storage device includes a flash memory and a controller. The flash memory stores a firmware. The firmware includes a plurality of mode page settings, and each mode page setting includes a plurality of mode parameters. The controller receives a mode selection command and a data out message arranged to rewrite a first mode page setting among the plurality of mode page settings from a host. The controller determines whether the data out message will change the mode parameters which cannot be rewritten in the first mode page setting according to the data out message. When the data out message will not change the mode parameters which cannot be rewritten in the first mode page setting, the controller determines whether a plurality of new mode parameters are kept in the flash after the data storage device is turned off.

CROSS REFERENCE TO RELATED APPLICATIONS

This application is a Continuation of application Ser. No. 15/886,012,filed Feb. 1, 2018 and entitled “DATA STORAGE DEVICE AND METHOD FORREWRITTING PARAMETERS THEREOF”, which claims the benefit of U.S.Provisional Application No. 62/453,567, filed on Feb. 2, 2017, andclaims priority of Taiwan Patent Application No. 107101540, filed onJan. 16, 2018, the entirety of which are incorporated by referenceherein.

BACKGROUND OF THE INVENTION Field of the Invention

The present invention relates to a method for rewriting parameters, andin particular, to a method for rewriting parameters that avoidsnon-rewritable parameters being changed.

Description of the Related Art

A flash memory is a common non-volatile data storage device, which canbe electrically erased and programmed. A non-gate type flash memory(i.e., NAND FLASH), for example, is commonly used as a memory card, auniversal serial bus (USB) flash device, a solid state drive (SSD), anembedded flash Memory module (eMMC), and so on.

In the operation of a flash memory, a controller accesses and maintainsthe flash memory according to a number of parameters. In general, theoperation parameters have default values, so that the flash memory canoperate in the appropriate environment. The user can rewrite theoperation parameters with specific commands. However, improper rewritingby the user may result in the flash memory operating in an inappropriateenvironment, such as long writing cycles or eliminating too much memoryspace. Therefore, a method is needed to avoid having the user changeparameters that cannot be rewritten, thereby preventing the flash memoryfrom operating improperly.

BRIEF SUMMARY OF THE INVENTION

The present invention provides a data storage device and a method forrewriting parameters which can reject a request for a non-rewritablemode parameter to be changed and notify the host 120 of it.

An exemplary embodiment of a data storage device is provided. The datastorage device comprises a flash memory and a controller. The flashmemory stores a firmware. The firmware comprises a plurality of modepage settings, and each mode page setting comprises a plurality of modeparameters. The controller receives a mode selection command and a dataout message from a host, wherein the data out message is arranged torewrite a first mode page setting among the plurality of mode pagesettings. The controller determines whether the data out message willchange the mode parameters which cannot be rewritten in the first modepage setting according to the data out message. When the data outmessage will not change the mode parameters which cannot be rewritten inthe first mode page setting, the controller determines whether aplurality of new mode parameters are kept in the flash after the datastorage device is turned off according to the mode selection command.

Moreover, when the data out message will not change the mode parameterswhich cannot be rewritten in the first mode page setting, the controllerreplies to the host with the UPIU response message indicating a successevent. When the data out message will change the mode parameters whichcannot be rewritten in the first mode page setting, the controllerreplies to the host with an UPIU response message indicating a failureevent.

In an embodiment, the controller receives the mode selection commandfrom the host. After the controller sends a ready-to-transfer message tothe host in response to the mode selection command, the controllerreceives the data out message which is sent by the host in response tothe ready-to-transfer message. The mode selection command comprises asave page parameter which is used to indicate whether the plurality ofnew mode parameters are kept after the data storage device is turnedoff. The controller determines that the plurality of new mode parametersare not kept in the flash memory after the data storage device is turnedoff when the save page parameter is “0”, and determines that theplurality of new mode parameters are kept in the flash memory after thedata storage device is turned off when the save page parameter is “1”.

In another embodiment, the controller fills the plurality of new modeparameters into a first array and performs a logic operation on thefirst array to determine whether the data out message will change themode parameters which cannot be rewritten in the first mode pagesetting. In derail, the controller fills preset values of the pluralityof mode parameters of the first mode page setting into a second array,performs an XOR logic operation on the first array and the second array,and fills a result of the XOR logic operation into a third array. Thecontroller performs an AND logic operation on the third array and afourth array and fills a result of the AND logic operation into a fiftharray. In the fourth array, bits corresponding to the mode parameterswhich cannot be rewritten are “1”, and bits corresponding to the modeparameters which can be rewritten are “0”. When any one of bits in thefifth array is a non-zero integer, the controller determines that thedata out message will change the mode parameters which cannot berewritten in the first mode page setting.

An exemplary embodiment of a method for rewriting parameters isprovided. The method for rewriting parameters is applied in a datastorage device which comprises a flash memory storing a firmware. Thefirmware comprises a plurality of mode page settings. Each mode pagesetting comprises a plurality of mode parameters. The method forrewriting parameters comprises steps of receiving a mode selectioncommand and a data out message from a host, wherein the data out messageis arranged to rewrite a first mode page setting among the plurality ofmode page settings; determining whether the data out message will changethe mode parameters which cannot be rewritten in the first mode pagesetting according to the data out message; and when the data out messagewill not change the mode parameters which cannot be rewritten in thefirst mode page setting, determining whether a plurality of new modeparameters are kept in the flash memory after the data storage device isturned off according to the mode selectin command.

Moreover, the method for rewriting parameters further comprises a stepof when the data out message will not change the mode parameters whichcannot be rewritten in the first mode page setting, replying to the hostwith the UPIU response message indicating a success event, and a step ofwhen the data out message will change the mode parameters which cannotbe rewritten in the first mode page setting, replying to the host withan UPIU response message indicating a failure event.

In an embodiment, the method for rewriting parameters further comprisessteps of sending a ready-to-transfer message to the host in response tothe mode selection command. The data out message is sent by the host inresponse to the ready-to-transfer message. The mode selection commandcomprises a save page parameter which is used to indicate whether theplurality of new mode parameters are kept after the data storage deviceis turned off. The method for rewriting parameters further comprisessteps of determining that the plurality of new mode parameters are notkept in the flash memory after the data storage device is turned offwhen the save page parameter is “0”, and determining that the pluralityof new mode parameters are kept in the flash memory after the datastorage device is turned off when the save page parameter is “1”.

Moreover, the step of determining whether the data out message willchange the mode parameters which cannot be rewritten in the first modepage setting according to the data out message comprises steps offilling the plurality of new mode parameters into a first array; andperforming a logic operation on the first array to determine whether thedata out message will change the mode parameters which cannot berewritten in the first mode page setting.

In an embodiment, the step of performing the logic operation on thefirst array comprises steps of filling preset values of the plurality ofmode parameters of the first mode page setting into a second array;performing an XOR logic operation on the first array and the secondarray; filling a result of the XOR logic operation into a third array;performing an AND logic operation on the third array and a fourth array;filling a result of the AND logic operation into a fifth array, whereinin the fourth array, bits corresponding to the mode parameters whichcannot be rewritten are “1”, and bits corresponding to the modeparameters which can be rewritten are “0”; when any one of bits in thefifth array is a non-zero integer, determining that the data out messagewill change the mode parameters which cannot be rewritten in the firstmode page setting; and when none of the bits in the fifth array is anon-zero integer, determining that the data out message will not changethe mode parameters which cannot be rewritten in the first mode pagesetting.

Moreover, the data storage device conforms to a specification ofuniversal flash storage (UFS). The plurality of mode page settingscomprise a control mode page setting, a read-write error mode pagesetting, and a caching mode page setting.

In an embodiment, the UPIU response message comprises a response field,a status field, a sense data [2] field, and a sense data [12]-[13]field. In the UPIU response message corresponding to the failure event,the response field is set as “TARGET FAILURE”, the status field is setas “CHECK CONDITION”, the sense data [2] field is set as “ILLEGALREQUEST”, and the sense data [12]-[13] field is set as “INVALID FIELD INPARAMETER LIST”. In the UPIU response message corresponding to thesuccess event, the response field is set as “TARGET SUCCESS”, the statusfield is set as “GOOD”. The data out message comprises a header and anew mode page setting. The new mode page setting corresponds to thefirst mode page setting and comprises a plurality of new mode parameterscorresponding to the plurality of mode parameters of the first mode pagesetting.

A detailed description is given in the following embodiments withreference to the accompanying drawings.

BRIEF DESCRIPTION OF THE DRAWINGS

The invention can be more fully understood by reading the subsequentdetailed description and examples with references made to theaccompanying drawings, wherein:

FIG. 1 is a block diagram of an exemplary embodiment of an electronicsystem;

FIG. 2 is a schematic diagram showing a data structure of a mode pagesetting according to an exemplary embodiment;

FIG. 3 is a flowchart of an exemplary embodiment of a method forrewriting parameters;

FIG. 4 is a schematic diagram showing a first array according to anexemplary embodiment; and

FIG. 5 is a schematic diagram showing a second array according to anexemplary embodiment.

DETAILED DESCRIPTION OF THE INVENTION

The following description is of the best-contemplated mode of carryingout the invention. This description is made for the purpose ofillustrating the general principles of the invention and should not betaken in a limiting sense. The scope of the invention is best determinedby reference to the appended claims.

FIG. 1 is a block diagram of an exemplary embodiment of an electronicsystem. An electronic system 100 comprises a host 120 and a data storagedevice 140. The data storage device 140 comprises a flash memory 180 anda controller 160 and operates in response to commands received from thehost 120. It should be noted that, in an embodiment, the data storagedevice 140 conforms to the specification of universal flash storage(UFS). In addition, the electronic system 100 may be implemented onanother computer-system configuration, such as a mobile device, amulti-processor system, a microprocessor-based or programmable consumerelectronic, a network computer, a minicomputer, a mainframe computer,and the like. For example, the electronic system 100 may be implementedin a mobile device, such as a mobile phone, a tablet, a smart watch, anda virtual reality device. The host 120 may be a central processing unit(CPU) or a microprocessor (MCU), and the data storage device 140 may bea memory device in the mobile device.

The controller 160 is configured to control the flash memory 180 basedon the firmware stored in the flash memory 180. The controller 160comprises a computation unit 162, a permanent memory 164 (ROM), and arandom access memory 166 (RAM). The permanent memory 164 and the programcodes loaded in the permanent memory 164 form a bootloader which isexecuted by the computation unit 162 to boot the data storage device140. The random access memory 166 is used for temporarily storing thedata and firmware which will be provided to and executed by thecomputation unit 162. The flash memory 180 comprises a plurality ofblocks, and each block comprises a plurality of pages for storing thefirmware of the data storage device 140 or data.

In an embodiment, the firmware comprises a plurality of mode pagesettings (i.e., SCSI mode settings). The mode page setting may comprisea control mode page setting, a read-write error mode page setting, and acaching mode page setting. Each of the mode page settings comprises aplurality of mode parameters. The controller 160 may operate based onthe mode parameters in each mode page setting. In an embodiment, thecontrol mode page setting can be used to provide control parameters(such as task set management and error logging) under a small computersystem interface for all devices; the read-write error mode page settingcan be used to set an error recovery parameter that the data storagedevice 140 should use to read/write the flash memory 180 under anycommand (e.g., a read command, a write command, or a confirm command);the caching mode page settings can be used to define how to use thecached parameters.

In an embodiment, the mode parameters of the control mode page setting,the read-write error mode page setting, and the caching mode pagesetting are respectively preset as preset mode parameters. The host 120may issue a mode select command to require the controller 160 to rewriteone of the mode page settings as a new mode page setting with newparameters different from the corresponding preset parameters. In anembodiment, the mode selection command may comprise a save pageparameter (SP parameter) to indicate whether the new mode parameters ofthe new mode page setting are kept after the data storage device 140 isturned off. For example, when the SP parameter of the mode selectioncommand is “0”, the controller 160 may rewrite the corresponding presetmode parameters temporarily stored in the random access memory 166 asnew mode parameters. When the SP parameter of the mode selection commandis “1”, the controller 160 may rewrite the corresponding preset modeparameters temporarily stored in the random access memory 166 as newmode parameters and simultaneously rewrite the corresponding presetparameters stored in the flash memory 180 as new mode parameters.

In an embodiment, most of the preset mode parameters in each mode pagesetting cannot be rewritten. If the host 120 instructs the controller160 to rewrite the mode parameters which cannot be rewritten, the datastorage device 140 cannot operate properly and normally. In anembodiment, except for the parameters of the software write protect(SWP), all of the other mode parameters in the control mode page settingare un-rewritable, wherein the parameter of software write protectionindicates whether to refuse (terminate) the write command received fromthe host 120 is required. In other words, the parameter of softwarewrite protection indicates that it necessary for the controller 160 toprohibit the write operation performed on the flash memory 180 after thedata is written into all the caches or buffer. For example, thearchitecture of the write command may comprise a format unit command,write (6), write (10), write (16), a synchronize cache command, a unmapcommand, and a verify command. If the parameter of the software writeprotection is set to “1”, the controller 160 may refuse the writecommand. If the parameter of the software write protection is set to“0”, the controller 160 may allow the write command to be executed.Therefore, when the parameter of the software write protection is “1”,all the commands related to the write operation of the flash memory 180are terminated, and the wrong information is returned, that is, an UFSprotocol information units (UPIU) response message is sent to the host120 after the termination. The UPIU response message (response UPIU)comprises a response field set as “TARGET FAILURE”, a status field setas “CHECK CONDITION”, a sense data[2] field (sense key) set as “DATAPROTECTION”, and a sense data[12]-[13] field (ASC & ASCQ) set as “WRITEPROTECTED”. The preset mode of the data storage device 140 may be anormal mode that allows the execution of the write command received fromthe host 120. When a new control mode page setting and its parameter ofthe software write protection is set to “1”, the data storage device 140may switch to a data protection mode that prohibits execution of a writecommand received from the host 120. When the data storage device 140receives a write command in the data protection mode, the data storagedevice 140 may reply the foregoing UPIU response message to the host120. Then, the data storage device 140 may continue to operate in thedata protection mode until a new control mode page setting with aparameter of the software write protection set to “0” is received. Thecontrol mode page setting with the parameter of the software writeprotection set to “0” may cause the data storage device 140 to switchback to the normal operation mode. In the embodiment of the presentinvention, UPIU is an abbreviation of the UFS protocol information unitsfor a flash memory.

In an embodiment, except for the parameters of the read retry count(RRC), the write retry count (WRC), and the recovery time limit (RTL),all of the other mode parameters in the read-write error mode pagesetting cannot be rewritten, wherein the parameter of the read retrycount indicates how many times preparation controller 160 needs toperform the recovery algorithms in the reading process, the parameter ofthe write retry count indicates how many times the controller 160 needsto perform the recovery algorithm in the writing process, and therecovery time limit indicates how long (millisecond) the controller 160can continuously perform the recovery process, but the present inventionis not limited thereto. In an embodiment, the data storage device 140may operate in a normal operation mode, a high read recovery mode, ahigh write recovery mode, and a high read-write recovery mode. Indetail, the data storage device 140 may be preset to operate in a normaloperation mode, wherein the parameters of the read retry count, thewrite retry count, and the recovery time limit may be preset as a firstvalue, a second value, and a third value, respectively. For example, thepreset parameters of the read retry count, the write retry count, andthe recovery time limit may be “0”, “0” and “0x4b0”, respectively. Whena new read-write error mode page setting with a parameter of the readretry count which is set as a fourth value is received, the data storagedevice 140 may be switched to the high read recovery mode, wherein thefourth value is a non-negative integer, and the fourth value is greaterthan the first value. In another embodiment, when a new read-write errormode page setting with a parameter of the write retry count which is setas a fifth value is received, the data storage device 140 may switch tothe high write recovery mode, wherein the fifth value is a non-negativeinteger, and the fifth value is greater than the second value. Inanother embodiment, when a new read-write error mode page setting with aparameter of the read retry count which is set as the fourth value and aparameter of the write retry count which is set as the fifth value isreceived, the data storage device 140 may receive is switch to the highread-write recovery mode.

In an embodiment, except for the parameters of the write back cacheenable (WCE) and the read cache disable (RCD) in the caching mode pagesetting, all of the other mode parameters cannot be rewritten. When theparameter of the write back cache enable “WCE” is set to “0”, the datastorage device 140 should complete the write command with a good status(i.e., replying a UPIU response message which comprises a response fieldset as “TARGET SUCCESS” and a status field set as “GOOD”) after all datais correctly written into the flash memory 180. When the parameter ofthe write back cache enable “WCE” is set to “1”, the data storage device140 can the write command with a good status after the correct data isreceived and before the data is written into the flash memory 180. Whenthe parameter of the read cache disable “RCD” is set to “0”, the datastorage device 140 may read the data required for the read command fromthe random access memory 166 or the flash memory 180 and transmit it tothe host 120. When the parameter of the read cache disable “RCD” is setto “1”, the data storage device 140 may read the data required for theread command only from the flash memory 180 and transmit it to the host120 (i.e., when the data required for the read command is stored in therandom access memory 166, the controller 160 needs to write therequested data to the flash memory 180 from the random access memory166, and then the controller 160 can read the required data from theflash memory 180 and transmit it to the host 120). In an embodiment, thedata storage device 140 has a normal operation mode, a write back cachedisable mode, and a read cache enable mode. The data storage device 140can be preset to operate in the normal operation mode, wherein in thepreset caching mode page setting, the parameter of the read cache accessdisable “RCD” is preset to “0” and the write back cache enable “WCE” ispreset to “1”. When a new caching mode page setting with a parameter ofthe read cache disable “RCD” set to “1” is received, the data storagedevice 140 may be switched from the normal operation mode to the readcache enable mode. When a new caching mode page setting with a parameterof the write back cache enable “WCE” set to “0” is received, the datastorage 140 may be switched from the normal operation mode to the writeback cache disable mode.

FIG. 2 is a schematic diagram showing a data structure of the mode pagesetting according to an exemplary embodiment. FIG. 2 shows a table 200for representing the bit data stored in the mode page setting. The datalength of the mode page setting is 3 bytes. The first row in the table200 shows that the data of the first byte in the mode page settingcomprises the bits A0, B0, C0-C5, the second row shows that the data ofthe second byte following the first byte in the mode page settingcomprises the bits D0-D7, and the third row shows that the third bytefollowing the second byte in the mode page setting comprises the bitsE0-E3, F0, G0-G1, and H0. In addition, each of the symbols A0, B0,C0-C5, D0-D7, E0-E3, F0, G0-G1, H0 is 1 bit (i.e., “0” or “1”). The bitA0 is a first mode parameter, the bit B0 is a second mode parameter, thebits C0-C5 form a third mode parameter, the bits D0-D7 form a fourthmode parameter, the bits E0-E3 form a fifth mode, the bit F0 is a sixthmode parameter, the bits G0-G1 form a seventh mode parameter, and thebit H0 is an eighth mode parameter. In other words, one mode parameteris composed of at least one bit, and the lengths of the mode parametersare not necessarily the same.

As mentioned above, the present invention further provides an embodimentwhich can prevents the host 120 from rewriting the mode parameters thatcannot be rewritten. In one embodiment, when the controller 160 receivesa mode selection command from the host 120, the controller 160 may sendback a ready-to-transfer message (ready-to-transfer UPIU) to cause thehost 120 to send a data out message (data out UPIU). The data outmessage comprises a header and a new mode page setting. In other words,the data out message comprises a message which indicates that the modepage setting needs to be rewritten and new mode parameters which need tobe written into the mode page setting.

In an embodiment, after obtaining new mode parameters, the controller160 needs to perform several determination processes. During thedetermination processes, the controller 160 needs to declare thevariable of each preset mode parameter and compare each new modeparameter with the corresponding preset mode parameter to determinewhich parameters are changed and whether the changed parameters are themode parameters which cannot be rewritten.

The above determination processes may take a considerable amount ofoperation time and resources of the controller 160. Therefore, thepresent invention further provides another embodiment for determiningwhether new mode parameters different from preset mode parameters cannotbe rewritten through using a specific logic operation and an array. Thedetailed process will be described by referring to the illustration ofFIG. 3.

FIG. 3 is a flowchart of an exemplary embodiment of a method forrewriting parameters. As shown in FIG. 3, in step S302, after obtainingnew mode parameters, the controller 160 fills the obtained new modeparameters into a first array RR1. As shown in FIG. 4, the first arrayARR1 comprises three elements EL0-EL2, the size of each element is 1byte for storing the parameters corresponding to one of the rows of themode page setting. In other words, the size of the first array ARR1corresponds to the size of the new mode page setting. For example, thecontroller 160 may obtain eight new mode parameters which correspond tothe mode parameters shown in FIG. 2, respectively. The obtained newparameters obtained comprise a new first mode parameter with a bit A0′,a new second mode parameter with a but B0′, a new third mode parameterwith bits C0′-C5′, a new fourth mode parameter with bits D0′-D7′, a newfifth mode parameter with bits E0′-E3′, a new sixth mode parameter witha bit F0′, a new seventh mode parameter with bits G0′-G1′, and a neweighth mode parameter with a bit H0′. Next, the controller 160 fills theeight bits A0′, B0′, and C0′-C5′ corresponding to the first row of thetable 200 into the first element EL0 of the first array ARR1, fills theeight bits D0′-D7′ and E0′ corresponding to the second row of the table200 into the second element EL1 of the first array ARR1, and furtherfills the eight bits E1′-E3′, F0′, G0′-G1′, and H0′ corresponding to thethird row of the table 200 into the third element EL2 of the first arrayARR1. It is noted that the size of each element in the first array ARR1corresponds to the length of the bits in each row of the mode pagesetting. In other words, the size of the elements of the first arrayARR1 may be larger than one byte based on the size of each row of in themode page setting. The number of elements in the array is not limited tothe number of this embodiment. In addition, FIGS. 4 and 5 can bereferred for the structure of other arrays disclosed in the presentinvention.

Next, in step S304, the controller 160 performs an XOR logic operation(XOR operation) on the first array ARR1 and the second array ARR2 andfills the result of the XOR logic operation into a third array. Theelements EL0-EL2 of the second array ARR2 (as shown in FIG. 5) arefilled with preset mode parameters of the preset mode page setting (thepreset values of the mode parameters of the preset mode page setting),and the third array may represent the difference between the first arrayand the second array. Moreover, during the XOR logical operation, theXOR logic operation is performed on each set of the correspondingelements in the first array ARR1 and the second array ARR2. In detail,when the XOR logic operation is preformed, the controller 160 firstperforms the XOR logic operation on the bits in the element EL0 of thefirst array ARR1 and the bits in the element EL0 of the second arrayARR2 to obtain a first result, then, performs the XOR logic operation onthe bits in the element EL1 of the first array ARR1 and the bits in theelement EL1 of the second array ARR2 to obtain a second result, and thenperforms the XOR logic operation on the bits in the element EL2 of thefirst array ARR1 and the bits in the element EL2 of the second arrayARR2 to obtain a third result. Finally, the controller 160 fills thebits of the first result, the second result, and the third into theelements EL0-EL2 of the third array sequentially. As shown in FIG. 5,the preset mode parameters are the same as the mode parameters shown inFIG. 2, and the mode parameters of one byte are filled into one element.

Next, in step S306, the controller 160 performs an AND logic operationon the third array and a fourth array and fills the result of the ANDlogic operation into a fifth array. The AND logic operation is performedon each set of the corresponding elements in the third array and thefourth array, and the values of the fourth array represent which bit ofthe preset mode page setting cannot be rewritten. In detail, during theAND logic operation, the controller 160 performs the AND logic operationon the bits of the element EL0 in the third array and the bits in theelement EL0 of the fourth array to obtain a first result, then, performsthe AND logic operation on the bits in the element EL1 of the thirdarray and the bits in the element EL1 of the fourth array to obtain asecond result, and then performs the AND logic operation on the bits inthe element EL2 of the third array and the bits in the element EL2 ofthe fourth array to obtain a third result. Finally, the controller 160fills the bits of the first result, the second result, and the thirdinto the elements EL0-EL2 of the fifth array sequentially. For example,each element of the fourth array corresponds to one row of the presetmode page setting (i.e., 1 byte). If one bit in an element of the fourtharray is set to “1”, the parameter corresponding to the bit which is setto “1” is a parameter that cannot be rewritten in the preset page modesetting (that is, a non-rewritable mode parameter). If one bit in anelement of the fourth array is set to “0”, the parameter correspondingto the bit which is set to “0” is a parameter that can be rewritten inthe preset page mode setting (i.e., a rewritable mode parameter).Finally, in step S308, the controller 160 may determine whether the dataout message (data out UPIU) comprises a new mode page setting which willrewrite non-rewritable mode parameters according to the results of thefifth array. In detail, if any element of the fifth array comprises anynon-zero bit (i.e., the bit value is 1), a new mode parametercorresponding to the non-zero bit will change the non-writable modeparameter of the preset mode page setting. Therefore, when any elementof the fifth array comprises a non-zero bit, the process proceeds tostep S312; otherwise, the process proceeds to step S310. In step S312,the controller 160 rejects the mode selection command and replies“failure” to the host 120. In step S310, the controller 160 accepts themode selection command, rewrites the preset mode page setting, andreplies “success” to the host 120.

For example, the controller 160 obtains new mode parameters from thedata output message, wherein the new mode parameters comprise a newfirst mode parameter with a bit value “1” (A0′), a new second modeparameter with a bit value “0”(B0′), a new third mode parameter with abit value “001011”(C0′-C5′), a new fourth mode parameter with a bitvalue “00110001”(D0′-D7′), a new fifth mode parameter with a bit value“1101” (E0′-E3′), a new sixth mode parameter with a bit value “0” (F0′),a new seventh mode parameter with a bit value “00” (G0′-G1′), and a neweighth mode parameter with a bit value of “1” (H0′). Next, thecontroller 160 fills the obtained new mode parameters into the elementsof the first array ARR1 comprising. The first element EL0 of the firstarray ARR1 filled with the new mode parameters is “10001011” (A0′, B0′,C0′-C5′), the second element EL1 the first array ARR1 filled with thenew mode parameter is “00110001” (D0′-D7′), and the third element EL2the first array ARR1 filled with the new mode parameters is “11010001”(E0′-E3′, F0′, G0′-G1′, H0′). Moreover, the first element EL0 of thesecond array ARR2 filled with the preset mode parameters is “11001011”(A0, B0, C0-C5), the second element EL1 the second array ARR2 filledwith the preset mode parameter is “00110111” (D0-D7), and the thirdelement EL2 the second array ARR2 filled with the preset mode parametersis “11010001” (E0-E3, F0, G0-G1, H0). Next, the controller 160 performsthe XOR logic operation on the bits “10001011” in the element EL0 of thefirst array ARR1 and the bits “11001011” in the element EL0 of thesecond array ARR2 to obtain the first result “01000000”, then, performsthe XOR logic operation on the bits “00110001” in the element EL1 of thefirst array ARR1 and the bits “00110111” in the element EL1 of thesecond array ARR2 to obtain the second result “00000110”, and thenperforms the XOR logic operation on the bits “11010001” in the elementEL2 of the first array ARR1 and the bits “11010001” in the element EL2of the second array ARR2 to obtain the third result “00000000”. Finally,the control 160 fills the bits of the first result, the second result,and the third into the elements EL0-EL2 of the third array sequentially.From the obtained results, it is seen that the bit values in theelements EL0 corresponding to B0 and B0′ have changed, and the bitvalues in the elements EL1 corresponding to D5-D6 and D5′-D6′ havechanged. In other words, the new second mode parameter and the newfourth mode parameter are different from the preset second modeparameter and the fourth mode parameter respectively. Then, thecontroller 160 can determine whether the changed new second modeparameter and the changed new fourth mode parameter are non-changeableparameters through using the fourth array and the AND logic operation.

In the embodiment, it is assumed that only the second mode parameter(B0) and the fifth mode parameter (E0-E3) among the mode parameters canbe rewritten. Thus, in the fourth array, the bits in the element EL0 ofthe fourth array are set to “10111111”; the bits in element EL1 are setto “11111111”, and the bits in element EL2 are set to “00001111”. Theresults which are obtained by performing the AND logic operation on thethree elements of the third array and the three elements of the fourtharray are “00000000”, “00000110” and “00000000” respectively, whereinthe results are sequentially filled into the elements EL0-EL2 of thefifth array. From the results of the fifth array, it is seen that thebit values in the element EL1 corresponding to D5 and D6 are non-zero.Therefore, the controller 160 knows that the original fourth modeparameter that cannot be changed is rewritten by the new fourth modeparameter. Therefore, in the present embodiment, the controller 160rejects the mode selection command and replies “failure” to the host120.

In another embodiment, it is assumed that only the second mode parameter(B0) and the fourth mode parameter (D0-D7) among the mode parameters canbe rewritten. Thus, in the fourth array, the bits in the element EL0 areset to “10111111”, the bits in the element EL1 are set to “00000000”,and the bits in the element EL2 are set to “11111111”. The results whichare obtained by performing the AND logic operation on the three elementsof the third array and the three elements of the fourth array of logicalAND operation of the three elements in the third array and the fourtharray are respectively “00000000”, “00000000” and “00000000”, whereinthe results are sequentially filled into the elements EL0-EL2 of thefifth array. From the results of the fifth array, all the bit values arezero. Therefore, in the present embodiment, the controller 160 acceptsthe mode selection command, rewrites the preset mode page setting, andreplies “success” to the host 120.

In an embodiment, the controller 160 may reply to the host 120 of thesuccess event or the failure event by using a UPIU response message(response UPIU). The UPIU response message comprises a response field, astatus field, a sense data [2] field, and a sense data [12]-[13] field.For example, when the controller 160 replies to the host 120 of thefailure event, the response field, the status field, the sense data [2]field, and the sense data [12]-[13] field are set as “TARGET FAILURE”,“CHECK CONDITION”, “ILLEGAL REQUEST”, and “INVALID FIELD IN PARAMETERLIST”, respectively.

As shown in the above embodiments, the data storage device 100 mayreject the request for non-rewritable mode parameters to be changed andnotify the host 120 that the request has been rejected. In addition, thecontroller 160 may determine whether the non-rewriteable mode parameterswill be changed through using an array and a logic operation. Therefore,embodiments of the present invention can prevent the data storage device140 from operating in an improper environment and thereby improveperformance by determining whether the non-rewritable mode parameterswill be changed or not.

The methods, or certain aspects or portions thereof, may take the formof a program code embodied in tangible media, such as floppy diskettes,CD-ROMs, hard drives, or any other machine-readable (e.g.,computer-readable) storage medium, or computer program products withoutlimitation in external shape or form thereof, wherein, when the programcode is loaded into and executed by a machine, such as a computer, themachine thereby becomes an apparatus for practicing the methods. Themethods may also be embodied in the form of a program code transmittedover some transmission medium, such as an electrical wire or a cable, orthrough fiber optics, or via any other form of transmission, wherein,when the program code is received and loaded into and executed by amachine, such as a computer, the machine becomes an apparatus forpracticing the disclosed methods. When implemented on a general-purposeprocessor, the program code combines with the processor to provide aunique apparatus that operates analogously to application specific logiccircuits.

While the invention has been described by way of example and in terms ofthe preferred embodiments, it should be understood that the invention isnot limited to the disclosed embodiments. On the contrary, it isintended to cover various modifications and similar arrangements (aswould be apparent to those skilled in the art). Therefore, the scope ofthe appended claims should be accorded the broadest interpretation so asto encompass all such modifications and similar arrangements.

What is claimed is:
 1. A data storage device comprising: a flash memorystoring a firmware, wherein the firmware comprises a plurality of modepage settings, and each mode page setting comprises a plurality of modeparameters; and a controller receiving a mode selection command and adata out message from a host, wherein the data out message is arrangedto rewrite a first mode page setting among the plurality of mode pagesettings, and further determining whether the data out message willchange the mode parameters which cannot be rewritten in the first modepage setting according to the data out message, wherein when the dataout message will not change the mode parameters which cannot berewritten in the first mode page setting, the controller determineswhether a plurality of new mode parameters are kept in the flash afterthe data storage device is turned off according to the mode selectioncommand.
 2. The data storage device as claimed in claim 1, wherein whenthe data out message will change the mode parameters which cannot berewritten in the first mode page setting, the controller replies to thehost with an UPIU response message indicating a failure event, whereinthe UPIU response message comprises a response field, a status field, asense data [2] field, and a sense data [12]-[13] field, and wherein inthe UPIU response message corresponding to the failure event, theresponse field is set as “TARGET FAILURE”, the status field is set as“CHECK CONDITION”, the sense data [2] field is set as “ILLEGAL REQUEST”,and the sense data [12]-[13] field is set as “INVALID FIELD IN PARAMETERLIST”.
 3. The data storage device as claimed in claim 1, wherein whenthe data out message will not change the mode parameters which cannot berewritten in the first mode page setting, the controller further repliesto the host with the UPIU response message indicating a success event,wherein the UPIU response message comprises a response field and astatus field, and wherein in the UPIU response message corresponding tothe success event, the response field is set as “TARGET SUCCESS”, thestatus field is set as “GOOD”.
 4. The data storage device as claimed inclaim 1, wherein the data out message comprises a header and a new modepage setting, and wherein the new mode page setting corresponds to thefirst mode page setting and comprises the plurality of new modeparameters corresponding to the plurality of mode parameters of thefirst mode page setting.
 5. The data storage device as claimed in claim4, wherein after the controller sends a ready-to-transfer message to thehost in response to the mode selection command, the controller receivesthe data out message which is sent by the host in response to theready-to-transfer message.
 6. The data storage device as claimed inclaim 5, wherein the mode selection command comprises a save pageparameter which is used to indicate whether the plurality of new modeparameters are kept after the data storage device is turned off.
 7. Thedata storage device as claimed in claim 6, wherein the controllerdetermines that the plurality of new mode parameters are not kept in theflash memory after the data storage device is turned off when the savepage parameter is “0”, and determines that the plurality of new modeparameters are kept in the flash memory after the data storage device isturned off when the save page parameter is “1”.
 8. The data storagedevice as claimed in claim 4, wherein the controller fills the pluralityof new mode parameters into a first array and performs a logic operationon the first array to determine whether the data out message will changethe mode parameters which cannot be rewritten in the first mode pagesetting.
 9. The data storage device as claimed in claim 8, wherein thecontroller fills preset values of the plurality of mode parameters ofthe first mode page setting into a second array, performs an XOR logicoperation on the first array and the second array, and fills a result ofthe XOR logic operation into a third array wherein the controllerperforms an AND logic operation on the third array and a fourth arrayand fills a result of the AND logic operation into a fifth array,wherein in the fourth array, bits corresponding to the mode parameterswhich cannot be rewritten are “1”, and bits corresponding to the modeparameters which can be rewritten are “0”, and wherein when any one ofbits in the fifth array is a non-zero integer, the controller determinesthat the data out message will change the mode parameters which cannotbe rewritten in the first mode page setting.
 10. A method for rewritingparameters applied in a data storage device which comprises a flashmemory storing a firmware, the firmware comprising a plurality of modepage settings, each mode page setting comprising a plurality of modeparameters, and the method for rewriting parameters comprising:receiving a mode selection command and a data out message from a host,wherein the data out message is arranged to rewrite a first mode pagesetting among the plurality of mode page settings; determining whetherthe data out message will change the mode parameters which cannot berewritten in the first mode page setting according to the data outmessage; and when the data out message will not change the modeparameters which cannot be rewritten in the first mode page setting,determining whether a plurality of new mode parameters are kept in theflash memory after the data storage device is turned off according tothe mode selectin command.
 11. The method for rewriting parameters asclaimed in claim 10, further comprising: when the data out message willchange the mode parameters which cannot be rewritten in the first modepage setting, replying to the host with an UPIU response messageindicating a failure event, wherein the UPIU response message comprisesa response field, a status field, a sense data [2] field, and a sensedata [12]-[13] field, and wherein in the UPIU response messagecorresponding to the failure event, the response field is set as “TARGETFAILURE”, the status field is set as “CHECK CONDITION”, the sense data[2] field is set as “ILLEGAL REQUEST”, and the sense data [12]-[13]field is set as “INVALID FIELD IN PARAMETER LIST”.
 12. The method forrewriting parameters as claimed in claim 10, further comprising: whenthe data out message will not change the mode parameters which cannot berewritten in the first mode page setting, replying to the host with theUPIU response message indicating a success event.
 13. The method forrewriting parameters as claimed in claim 12, wherein the UPIU responsemessage comprises a response field and a status field, and wherein inthe UPIU response message corresponding to the success event, theresponse field is set as “TARGET SUCCESS”, the status field is set as“GOOD”.
 14. The method for rewriting parameters as claimed in claim 10,wherein the data out message comprises a header and a new mode pagesetting, and wherein the new mode page setting corresponds to the firstmode page setting and comprises the plurality of new mode parameterscorresponding to the plurality of mode parameters of the first mode pagesetting.
 15. The method for rewriting parameters as claimed in claim 14further comprising: sending a ready-to-transfer message to the host inresponse to the mode selection command, wherein the data out message issent by the host in response to the ready-to-transfer message.
 16. Themethod for rewriting parameters as claimed in claim 15, wherein the modeselection command comprises a save page parameter which is used toindicate whether the plurality of new mode parameters are kept after thedata storage device is turned off.
 17. The method for rewritingparameters as claimed in claim 16, wherein, when the save page parameteris “0”, determining that the plurality of new mode parameters are notkept in the flash memory after the data storage device is turned off;and when the save page parameter is “1”, determining that the pluralityof new mode parameters are kept in the flash memory after the datastorage device is turned off.
 18. The method for rewriting parameters asclaimed in claim 14, wherein the step of determining whether the dataout message will change the mode parameters which cannot be rewritten inthe first mode page setting according to the data out message comprises:filling the plurality of new mode parameters into a first array; andperforming a logic operation on the first array to determine whether thedata out message will change the mode parameters which cannot berewritten in the first mode page setting.
 19. The method for rewritingparameters as claimed in claim 18, wherein the step of performing thelogic operation on the first array comprises: filling preset values ofthe plurality of mode parameters of the first mode page setting into asecond array; performing an XOR logic operation on the first array andthe second array; and filling a result of the XOR logic operation into athird array.
 20. The method for rewriting parameters as claimed in claim19, wherein the step of performing the logic operation on the firstarray further comprises: performing an AND logic operation on the thirdarray and a fourth array; filling a result of the AND logic operationinto a fifth array, wherein in the fourth array, bits corresponding tothe mode parameters which cannot be rewritten are “1”, and bitscorresponding to the mode parameters which can be rewritten are “0”,when any one of bits in the fifth array is a non-zero integer,determining that the data out message will change the mode parameterswhich cannot be rewritten in the first mode page setting; and when noneof the bits in the fifth array is a non-zero integer, determining thatthe data out message will not change the mode parameters which cannot berewritten in the first mode page setting.